package com.example.SBootDemo.Util.MINA.code;


import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoder;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;

import com.example.SBootDemo.Util.MINA.infoModel.DeviceModel;

/**
 * 编码
 * @author 944658413
 *
 */
public class Encoder implements ProtocolEncoder {

	@Override
	public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
		// TODO Auto-generated method stub
		 
	        IoBuffer buffer = IoBuffer.allocate(1000, false);  
	        String mes=message.toString();
	        System.out.println("编码器--要发送的消息"+mes);
	        buffer.putString(mes, Charset.forName("utf-8").newEncoder() ) ;
	        buffer.flip();  
	        out.write(buffer);  
	}

	@Override
	public void dispose(IoSession session) throws Exception {
		// TODO Auto-generated method stub
		
	}

}
